package yto.freemarker.springbootstudy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yto.freemarker.springbootstudy.service.MailService;

/**
 * 发送邮件的Controller
 *
 * @author dongxing
 * @create 2018-04-03 8:58
 **/
@RestController
@RequestMapping("/c")
public class MailController {

    @Autowired
    private MailService mailService;

    private final String RECEIVER = "maxinecho@163.com";

    /**
     * 简单发送
     *
     * @return
     */
    @RequestMapping("/sendSimpleMail")
    public ResponseEntity<?> sendSimpleMail() {
        mailService.sendSimpleMail(RECEIVER, "简单邮件", "简单的邮件测试");
        return ResponseEntity.ok(true);
    }

    /**
     * 发送html内容
     *
     * @return
     */
    @RequestMapping("/sendHtmlMail")
    public ResponseEntity<?> sendHtmlMail() {
        mailService.sendHtmlMail(RECEIVER, "html邮件", "<html><body><h3>你好， 这是一封模板邮件!</h3></body></html>");
        return ResponseEntity.ok(true);
    }

    /**
     * 发送附件
     *
     * @return
     */
    @RequestMapping("/sendAttachmentsMail")
    public ResponseEntity<?> sendAttachmentsMail() {
        mailService.sendAttachmentsMail(RECEIVER, "附件邮件", "测试邮件内容", "D:\\你好.txt");
        return ResponseEntity.ok(true);
    }

    /**
     * 发送图片
     *
     * @return
     */
    @RequestMapping("/sendInlineResourceMail")
    public ResponseEntity<?> sendInlineResourceMail() {
        mailService.sendInlineResourceMail(RECEIVER, "发送图片", "<img src=\"cid:rscId01\" >", "D:\\1.jpg", "rscId01");
        return ResponseEntity.ok(true);
    }
}
